package thread.ch04;

import java.util.Vector;

import thread.annotation.ThreadSafe;

/**
 * 扩展的vector包含一个“缺少即加入”方法
 * <p />
 * vector的同步策略已由其规约固定住，所以BetterVector不会遇到这问题
 * @author Edgar Zhang
 *
 * @param <E>
 */
@ThreadSafe
public class BetterVector<E> extends Vector<E> {

	public synchronized boolean putIfAbsent(E x) {
		boolean absent = !contains(x);
		if (absent) {
			add(x);
		}
		return absent;
	}
}
